package org.jeecg.util;

import java.net.InetSocketAddress;
import java.util.HashMap;
import java.util.Map;

public class DeviceSession {
    private InetSocketAddress address;
    private byte[] deviceInfo;
    private Map<Short, Byte> alarmEnableStatus = new HashMap<>();
    private Map<Short, Byte> alarmStatus = new HashMap<>();

    public DeviceSession(InetSocketAddress address) {
        this.address = address;
        initializeDefaultStatus();
    }

    private void initializeDefaultStatus() {
        // 初始化默认告警使能状态
        for (int id = ProtocolConstants.ALARM_ENABLE_START;
             id <= ProtocolConstants.ALARM_ENABLE_END; id++) {
            alarmEnableStatus.put((short)id, (byte)1); // 默认使能
        }
    }

    // getter/setter 方法
    public InetSocketAddress getAddress() { return address; }
    public byte[] getDeviceInfo() { return deviceInfo; }
    public void setDeviceInfo(byte[] info) { deviceInfo = info; }

    public byte getAlarmEnableStatus(short alarmId) {
        return alarmEnableStatus.getOrDefault(alarmId, (byte)0);
    }

    public void setAlarmEnableStatus(short alarmId, byte status) {
        alarmEnableStatus.put(alarmId, status);
    }

    public byte getAlarmStatus(short alarmId) {
        return alarmStatus.getOrDefault(alarmId, (byte)0);
    }

    public void updateAlarmStatus(short alarmId, byte status) {
        alarmStatus.put(alarmId, status);
    }
}